home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / gui / select_gc.lha / select_gc / SelGadgTest.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-30  |  9.2 KB  |  259 lines

  1.  
  2.  
  3. /*  Select.gadget test (25.5.98)  */
  4. /*  Written for SAS/C             */
  5. /*  Compile: SC LINK SelGadgTest  */
  6. /*  © 1998 Massimo Tantignone     */
  7.  
  8.  
  9. #include "exec/types.h"
  10. #include "dos/dos.h"
  11. #include "intuition/intuition.h"
  12. #include "intuition/gadgetclass.h"
  13. #include "libraries/gadtools.h"
  14. #include "proto/intuition.h"
  15. #include "proto/exec.h"
  16.  
  17. #include <gadgets/select.h>
  18. #include <clib/selectgadget_protos.h>
  19. #include <pragmas/selectgadget_pragmas.h>
  20.  
  21.  
  22. /* The library base for the "select.gadget" class library */
  23.  
  24. struct Library *SelectGadgetBase;
  25.  
  26.  
  27. ULONG main(void)
  28. {
  29.    /* The usual stuff */
  30.  
  31.    struct Screen *scr;
  32.    struct Window *win;
  33.    struct IntuiMessage *imsg;
  34.    struct DrawInfo *dri;
  35.    ULONG class, code, fine = FALSE;
  36.    ULONG width = 640, height = 200;
  37.    struct Gadget *gad1, *gad2, *gad3, *gad4;
  38.    struct Gadget *iaddress;
  39.    STRPTR labels1[] = { "First option",
  40.                         "Second option",
  41.                         "Third option",
  42.                         "Fourth option",
  43.                         NULL };
  44.    STRPTR labels2[] = { "This is an",
  45.                         "example of",
  46.                         "my BOOPSI",
  47.                         "pop-up",
  48.                         "gadget class.",
  49.                         NULL };
  50.  
  51.    /* Let's try to open the "select.gadget" library any way we can */
  52.  
  53.    SelectGadgetBase = OpenLibrary("select.gadget",40L);
  54.  
  55.    if (!SelectGadgetBase)
  56.       SelectGadgetBase = OpenLibrary("Gadgets/select.gadget",40L);
  57.  
  58.    if (!SelectGadgetBase)
  59.       SelectGadgetBase = OpenLibrary("Classes/Gadgets/select.gadget",40L);
  60.  
  61.    /* Really not found? Then quit (and complain a bit) */
  62.  
  63.    if (!SelectGadgetBase) return (RETURN_FAIL);
  64.  
  65.    /* Inquire about the real screen size */
  66.  
  67.    if (scr = LockPubScreen(NULL))
  68.    {
  69.       width = scr->Width;
  70.       height = scr->Height;
  71.       UnlockPubScreen(NULL,scr);
  72.    }
  73.  
  74.    /* Open a window on the default public screen */
  75.  
  76.    if (win = OpenWindowTags(NULL,WA_Left,(width - 500) / 2,
  77.                                  WA_Top,(height - 160) / 2,
  78.                                  WA_Width,500,WA_Height,160,
  79.                                  WA_MinWidth,100,WA_MinHeight,100,
  80.                                  WA_MaxWidth,-1,WA_MaxHeight,-1,
  81.                                  WA_CloseGadget,TRUE,
  82.                                  WA_SizeGadget,TRUE,
  83.                                  WA_DepthGadget,TRUE,
  84.                                  WA_DragBar,TRUE,
  85.                                  WA_SimpleRefresh,TRUE,
  86.                                  WA_Activate,TRUE,
  87.                                  WA_Title,"select.gadget test",
  88.                                  WA_IDCMP,IDCMP_CLOSEWINDOW |
  89.                                           IDCMP_GADGETUP |
  90.                                           IDCMP_REFRESHWINDOW,
  91.                                  TAG_END))
  92.    {
  93.       /* Get the screen's DrawInfo, it will be useful... */
  94.  
  95.       if (dri = GetScreenDrawInfo(win->WScreen))
  96.       {
  97.          /* A standard pop-up gadget, with some attributes overridden */
  98.  
  99.          gad1 = NewObject(NULL,"selectgclass",GA_Left,40,
  100.                                               GA_Top,40 + win->BorderTop,
  101.                                               GA_RelVerify,TRUE,
  102.                                               GA_DrawInfo,dri,
  103.                                               GA_Text,"Click me",
  104.                                               GA_ID,1,
  105.                                               SGA_TextPlace,PLACETEXT_ABOVE,
  106.                                               SGA_Labels,labels1,
  107.                                               SGA_Separator,FALSE,
  108.                                               SGA_ItemSpacing,2,
  109.                                               SGA_FollowMode,SGFM_FULL,
  110.                                               SGA_MinTime,200,
  111.                                               SGA_MaxTime,200,
  112.                                               SGA_PanelMode,SGPM_DIRECT_NB,
  113.                                               TAG_END);
  114.  
  115.          /* A "quiet" pop-up gadget, which could be attached to another one */
  116.  
  117.          gad2 = NewObject(NULL,"selectgclass",GA_Previous,gad1,
  118.                                               GA_Top,80 + win->BorderTop,
  119.                                               GA_RelVerify,TRUE,
  120.                                               GA_DrawInfo,dri,
  121.                                               GA_Text,"Me, too!",
  122.                                               GA_ID,2,
  123.                                               SGA_Labels,labels2,
  124.                                               SGA_PopUpPos,SGPOS_RIGHT,
  125.                                               SGA_Quiet,TRUE,
  126.                                               SGA_Separator,FALSE,
  127.                                               SGA_ReportAll,TRUE,
  128.                                               SGA_BorderSize,8,
  129.                                               SGA_FullPopUp,TRUE,
  130.                                               SGA_PopUpDelay,1,
  131.                                               SGA_DropShadow,TRUE,
  132.                                               SGA_ListJustify,SGJ_LEFT,
  133.                                               TAG_END);
  134.  
  135.          /* Let's make it perfectly square, and place it correctly */
  136.  
  137.          if (gad1 && gad2)
  138.          {
  139.             SetAttrs(gad2,GA_Left,gad1->LeftEdge + gad1->Width - gad2->Height,
  140.                           GA_Width,gad2->Height,
  141.                           TAG_END);
  142.          }
  143.  
  144.          /* A "sticky" list-type pop-up gadget */
  145.  
  146.          gad3 = NewObject(NULL,"selectgclass",GA_Previous,gad2,
  147.                                               GA_Top,40 + win->BorderTop,
  148.                                               GA_RelVerify,TRUE,
  149.                                               GA_DrawInfo,dri,
  150.                                               GA_Text,"Sticky b_utton",
  151.                                               GA_ID,3,
  152.                                               SGA_Underscore,'_',
  153.                                               SGA_Labels,labels1,
  154.                                               SGA_Active,3,
  155.                                               SGA_ItemSpacing,4,
  156.                                               SGA_SymbolOnly,TRUE,
  157.                                               SGA_SymbolWidth,-21,
  158.                                               SGA_Sticky,TRUE,
  159.                                               SGA_PopUpPos,SGPOS_BELOW,
  160.                                               SGA_BorderSize,4,
  161.                                               SGA_PopUpDelay,1,
  162.                                               TAG_END);
  163.  
  164.          /* Let's place it correctly */
  165.  
  166.          if (gad3)
  167.          {
  168.             SetAttrs(gad3,GA_Left,win->Width - gad3->Width - 40,TAG_END);
  169.          }
  170.  
  171.          /* A pop-up gadget which simply reflects the global user settings */
  172.  
  173.          gad4 = NewObject(NULL,"selectgclass",GA_Previous,gad3,
  174.                                               GA_Top,80 + win->BorderTop,
  175.                                               GA_RelVerify,TRUE,
  176.                                               GA_DrawInfo,dri,
  177.                                               GA_Text,"S_imple",
  178.                                               GA_ID,4,
  179.                                               SGA_Underscore,'_',
  180.                                               SGA_Labels,labels1,
  181.                                               TAG_END);
  182.  
  183.          /* Let's place it correctly */
  184.  
  185.          if (gad4)
  186.          {
  187.             SetAttrs(gad4,GA_Left,win->Width - gad4->Width - 40,TAG_END);
  188.          }
  189.  
  190.          /* If all went ok, add the gadgets to the window and display them */
  191.  
  192.          if (gad1 && gad2 && gad3 && gad4)
  193.          {
  194.             AddGList(win,gad1,-1,-1,NULL);
  195.             RefreshGList(gad1,win,NULL,-1);
  196.          }
  197.  
  198.          /* Now let's handle the events until the window gets closed */
  199.  
  200.          while (!fine)
  201.          {
  202.             Wait(1 << win->UserPort->mp_SigBit);
  203.  
  204.             while (imsg = (struct IntuiMessage *)GetMsg(win->UserPort))
  205.             {
  206.                class = imsg->Class;
  207.                code = imsg->Code;
  208.                iaddress = imsg->IAddress;
  209.                ReplyMsg((struct Message *)imsg);
  210.  
  211.                if (class == IDCMP_CLOSEWINDOW) fine = TRUE;
  212.  
  213.                if (class == IDCMP_GADGETUP) printf("Gadget: %ld, Item: %ld\n",
  214.                                                    iaddress->GadgetID,
  215.                                                    code);
  216.  
  217.                if (class == IDCMP_REFRESHWINDOW)
  218.                {
  219.                   BeginRefresh(win);
  220.                   EndRefresh(win,TRUE);
  221.                }
  222.             }
  223.          }
  224.  
  225.          /* If the gadgets were added, remove them */
  226.  
  227.          if (gad1 && gad2 && gad3 && gad4)
  228.          {
  229.             RemoveGList(win,gad1,4);
  230.          }
  231.  
  232.          /* Dispose the gadgets; DisposeObject() ignores NULL arguments */
  233.  
  234.          DisposeObject(gad1);
  235.          DisposeObject(gad2);
  236.          DisposeObject(gad3);
  237.          DisposeObject(gad4);
  238.  
  239.          /* Release the DrawInfo structure */
  240.  
  241.          FreeScreenDrawInfo(win->WScreen,dri);
  242.       }
  243.  
  244.       /* Say good-bye to the window... */
  245.  
  246.       CloseWindow(win);
  247.    }
  248.  
  249.    /* ... and to the library */
  250.  
  251.    CloseLibrary(SelectGadgetBase);
  252.  
  253.    /* We did our job, now let's go home :-) */
  254.  
  255.    return (RETURN_OK);
  256. }
  257.  
  258.  
  259.